<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <title>Document</title>
    </head>
    <body>
        <form action="" id="form">
            <p>
                <label for="username">请输入用户名</label>
                <input type="text" id="username" name="username" required minlength="1" maxlength="3"/>
            </p>
            <input type="submit" id="submitForm" value="提交"/>
        </form>
        <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/lib/jquery.js"></script>
        <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js"></script>
        <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/localization/messages_zh.js"></script>
        <script>
        $.validator.addMethod('af',function(value,element,params){
            if(value.length>1){
                return false;
            }
            if(value>=params[0] && value<=params[1]){
                return true;
            }else{
                return false;
            }
        },'必须是一个字母,且a-f')
        $().ready(function(){
            $("#form").validate({
                rules:{
                    username:{
                        af:['a','f']
                    }
                }
            })
        })
        </script>
    </body>
</html>